package com.ddh.ddhsanguogame.exception;

import com.ddh.ddhsanguogame.common.BaseResponse;
import com.ddh.ddhsanguogame.common.DongResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(DongException.class)
    public BaseResponse<?> businessExceptionHandler(DongException e) {
        log.error("BusinessException", e);
        return DongResultUtils.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> businessExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        return DongResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误");
    }
}
